package com.scau.yangsuiyu.estore.service;

import com.alibaba.fastjson.JSONObject;
import com.scau.yangsuiyu.estore.dababases.dao.GoodsDao;
import com.scau.yangsuiyu.estore.dababases.entity.Goods;

import java.sql.Timestamp;

/**
 * @author suiyu_yang
 * @description 添加商品Service
 * @date 2019-05-23 18:20
 * @email suiyu_yang@163.com
 */
public class GoodsService {
    private Goods goods;

    public GoodsService(Goods goods) {
        this.goods = goods;
    }

    public JSONObject addGoods() {
        goods.setCreateTime(new Timestamp(System.currentTimeMillis()));
        goods.setDisable(false);
        goods.setSales(0);
        JSONObject resultJson = new JSONObject();
        resultJson.put("status", "success");
        resultJson.put("result", "添加商品成功！");
        resultJson.put("goods", goods);

        new GoodsDao().insert(goods);

        return resultJson;
    }

    public JSONObject updateGoods() {
        goods.setLastUpdateTime(new Timestamp(System.currentTimeMillis()));

        JSONObject resultJson = new JSONObject();
        resultJson.put("status", "success");
        resultJson.put("result", "修改商品成功！");
        resultJson.put("goods", goods);

        new GoodsDao().update(goods);

        return resultJson;
    }

}
